package com.systop.busafter.location.controller;
import com.systop.busafter.location.service.LocationService;
import com.systop.commer.ResponseResult;
import com.systop.commer.pojo.Location;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class LocationController {
    @Autowired
    private LocationService locationService;
    //通过id修改
    @RequestMapping(value="/updatalocation",method= RequestMethod.POST)
    public @ResponseBody
    ResponseResult updatalocation(@RequestBody Location location){
        int i =  locationService.updatalocation(location);
        if (i == 0) {
            return ResponseResult.build(500, "修改失败");
        } else {
            return ResponseResult.build(200, "修改成功", i);
        }
    }
    //通过司机id修改状态
    @RequestMapping(value="/uplocationdriver",method= RequestMethod.POST)
    public @ResponseBody
    ResponseResult uplocationdriver(@RequestBody Location location){
        int i =  locationService.uplocationdriver(location);
        if (i == 0) {
            return ResponseResult.build(500, "修改失败");
        } else {
            return ResponseResult.build(200, "修改成功", i);
        }
    }
    //添加
    @RequestMapping(value="/insertlocation",method= RequestMethod.POST)
    public @ResponseBody
    ResponseResult insertlocation(@RequestBody Location location){
        int i =  locationService.insertlocation(location);
        if (i == 0) {
            return ResponseResult.build(500, "添加失败");
        } else {
            return ResponseResult.build(200, "添加成功", i);
        }
    }

    //查看全部
    @RequestMapping(value="/locationListall",method= RequestMethod.POST)
    public @ResponseBody
    ResponseResult locationListall(){
        List<Location> list =  locationService.locationListall();
        if (list == null) {
            return ResponseResult.build(500, "查看失败");
        } else {
            return ResponseResult.build(200, "查看成功", list);
        }
    }
    //通过id查List
    @RequestMapping(value="/locationIdlist",method= RequestMethod.POST)
    public @ResponseBody
    ResponseResult locationIdlist(@RequestParam(value = "location_id")int location_id){
        List<Location> list =  locationService.locationIdlist(location_id);
        if (list == null) {
            return ResponseResult.build(500, "查看失败");
        } else {
            return ResponseResult.build(200, "查看成功", list);
        }
    }
    //通过id查实体类
    @RequestMapping(value="/LocationId",method= RequestMethod.POST)
    public @ResponseBody
    ResponseResult LocationId(@RequestParam(value = "location_id")int location_id){
        Location l =  locationService.LocationId(location_id);
        if (l == null) {
            return ResponseResult.build(500, "查看失败");
        } else {
            return ResponseResult.build(200, "查看成功", l);
        }
    }
    //删除
    @RequestMapping(value="/deletelocation",method= RequestMethod.POST)
    public @ResponseBody
    ResponseResult deletelocation(@RequestParam(value = "location_id")int location_id){
       int i =  locationService.deletelocation(location_id);
        if (i == 0) {
            return ResponseResult.build(500, "删除失败");
        } else {
            return ResponseResult.build(200, "删除成功", i);
        }
    }
    //通过司机id查
    @RequestMapping(value="/locationdriverid",method= RequestMethod.POST)
    public @ResponseBody
    ResponseResult locationdriverid(@RequestParam(value = "location_driver_id")int location_driver_id){
        List<Location> list =  locationService.locationdriverid(location_driver_id);
        if (list == null) {
            return ResponseResult.build(500, "查看失败");
        } else {
            return ResponseResult.build(200, "查看成功", list);
        }
    }
    //通过司机id查和状态查
    @RequestMapping(value="/locationdriverids",method= RequestMethod.POST)
    public @ResponseBody
    ResponseResult locationdriverids(@RequestBody Location location){
        List<Location> a =  locationService.locationdriverids(location);
        if (a.size() == 0) {
            return ResponseResult.build(500, "查看失败");
        } else {
            return ResponseResult.build(200, "查看成功", a);
        }
    }

}
